﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Web;
using nplJobsCommon.Common;
using nplJobsBLL.Common;
using nplJobsCommon.Employeer;
using nplJobsBLL.ProcessEmployeer;
using System.Web.Security;

namespace nplJobsWebSite
{
    public static class Common
    {
        public static List<City> GetCity()
        {

            return null;
        }

        public static void BindDDLCity(System.Web.UI.WebControls.DropDownList ddl)
        {
            City obj = new City();
            obj.COUNTRYID = 0;
            List<City> lst = ProcessSelectCity.GetList(obj, "");

            if (lst != null)
            {
                ddl.DataSource = lst;
                ddl.DataValueField = "ID";
                ddl.DataTextField = "Name";
                ddl.DataBind();
            }


        }

        public static void BindAllJobCategory(System.Web.UI.WebControls.DropDownList control)
        {
            JobCategory obj = new JobCategory();

            List<JobCategory> lst = JobCategoryBLL.GetList(obj, "S");

            if (lst != null)
            {
                control.DataSource = lst;
                control.DataValueField = "ID";
                control.DataTextField = "Caterogy";
                control.DataBind();
            }

            control.Items.Insert(0, "Select Category");
        }

        public static void BindEmployment(System.Web.UI.WebControls.ListBox ddl)
        {
            try
            {
                List<EmploymentType> lst = EmploymentTypeBLL.GetList(new EmploymentType());

                if (lst != null)
                {
                    ddl.DataSource = lst;
                    ddl.DataValueField = "ID";
                    ddl.DataTextField = "EMPLOYMENTTYPE";
                    ddl.DataBind();
                }

            }
            catch (Exception)
            {
            }
        }

        public static void BindQualification(System.Web.UI.WebControls.ListBox ddl)
        {
            try
            {
                List<Qualification> lst = QualificationBLL.GetList(new Qualification());

                if (lst != null)
                {
                    ddl.DataSource = lst;
                    ddl.DataValueField = "ID";
                    ddl.DataTextField = "strQualification";
                    ddl.DataBind();
                }

            }
            catch (Exception)
            {
            }
        }

        #region GetEmployeer
        /// <summary>
        /// Get employeer by id
        /// </summary>
        /// <param name="employeerId"></param>
        /// <returns></returns>

        public static Employeer GetEmployeer(Guid employeerId)
        {
            Employeer employeer = new Employeer();
            ProcessSelectEmployeer selectEmployeer = new ProcessSelectEmployeer();
            selectEmployeer.employeerID = employeerId;
            selectEmployeer.invoke();

            if (selectEmployeer.Employeer != null)
            {
                employeer = selectEmployeer.Employeer.FirstOrDefault();
            }

            if (employeer != null)
            {
                //Get Employeer Contact Person by employeer id
                ProcesEmployeerContactPerson procesEmployeerContactPerson = new ProcesEmployeerContactPerson();
                procesEmployeerContactPerson.employeerID = employeerId;
                procesEmployeerContactPerson.contactPersonID = employeer.ContactPersonID;
                procesEmployeerContactPerson.invoke();
                employeer.EmployeerContactPerson = procesEmployeerContactPerson.employeerContactPerson.FirstOrDefault();
            }
            return employeer;
        }
        #endregion
        
        public static MembershipUser CurrentMembershipUser
        {
            get
            {
                if (HttpContext.Current.Session["userInfo"] != null)
                    return (MembershipUser)HttpContext.Current.Session["userInfo"];
                else
                    return null;
            }
        }

    }
}